package com.sc.springboot.service.impl;

import com.sc.springboot.bean.User;
import com.sc.springboot.dao.UserDao;
import com.sc.springboot.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserDao userDao;

    @Override
    public boolean add(User user) {
        try {
            userDao.add(user);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean delete(User user) {
        int id = user.getId();
        try {
            userDao.delete(id);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean update(User user) {
        try {
            userDao.update(user);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public List<User> findAll() {
        try {
            return userDao.findAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public User findByUserName(String userName) {
        try {
            return userDao.findByUserName(userName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
